package cn.com.zsw.gblog.modules.gblog.controller;

import cn.com.zsw.gblog.modules.gblog.dto.CategoryDTO;
import cn.com.zsw.gblog.modules.gblog.service.GbCategoryService;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (GbCategory)表控制层
 *
 * @author shiwangzhou
 * @since 2020-06-24 11:43:15
 */
@RestController
@RequestMapping("blog/category")
public class GbCategoryController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private GbCategoryService gbCategoryService;

    @GetMapping("list")
    public R getCategoryList() {
        return R.ok(gbCategoryService.getCategoryList());
    }

    @GetMapping("detail/{id}")
    public R detail(@PathVariable String id) {
        return R.ok(gbCategoryService.getById(id));
    }

    @GetMapping("name/list")
    public R getCategoryNameList() {
        return R.ok(gbCategoryService.getCategoryNameList());
    }

    /**
     * 新增或者更新
     *
     * @param categoryDTO
     * @return com.baomidou.mybatisplus.extension.api.R
     * @author shiwangzhou
     * @date 2021-06-03 16:58
     **/

    @PostMapping
    public R save(@RequestBody CategoryDTO categoryDTO) {
        return R.ok(gbCategoryService.save(categoryDTO));
    }

    /**
     * 根据id阐述分类
     *
     * @param categoryId 分类ID
     * @return com.baomidou.mybatisplus.extension.api.R
     * @author shiwangzhou
     * @date 2021-06-03 16:57
     **/
    @DeleteMapping
    public R getCategoryNameList(String categoryId) {
        return R.ok(gbCategoryService.removeById(categoryId));
    }

}